package com.cn.customer.housekeeping.housekeepingb.ui;

import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.TimePicker;

import com.cn.customer.housekeeping.housekeepingb.R;
import com.cn.customer.housekeeping.housekeepingb.bean.BaseResp;
import com.cn.customer.housekeeping.housekeepingb.bean.ProdctBean;
import com.cn.customer.housekeeping.housekeepingb.biz.personcenter.IUserLoginView;
import com.cn.customer.housekeeping.housekeepingb.biz.personcenter.InterfacePresenter;
import com.cn.customer.housekeeping.housekeepingb.ui.adapter.MyGridViewchoiceTimeAdpter;
import com.cn.customer.housekeeping.housekeepingb.ui.base.BaseActivity;
import com.cn.customer.housekeeping.housekeepingb.util.ToastUtil;
import com.cn.customer.housekeeping.housekeepingb.util.Utils;

import java.util.ArrayList;
import java.util.List;


/***
 * 选择营业时间
 */
public class ChoiceBusinessTimeActivity extends BaseActivity implements IUserLoginView {
    private TimePicker time_pickerkaishi, time_pickerjieshu;
    private TextView tv_timekaishi, tv_timejieshu;
    private InterfacePresenter mInterfacePresenter;
    private GridView gv_business;
    private List<ProdctBean> listDatas;
    private MyGridViewchoiceTimeAdpter mMyGridViewchoiceTimeAdpter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_choicebusinesstime);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initViews() {
        mInterfacePresenter = new InterfacePresenter();
        gv_business = (GridView) findViewById(R.id.gv_business);
        tv_timekaishi = (TextView) findViewById(R.id.tv_timekaishi);
        tv_timejieshu = (TextView) findViewById(R.id.tv_timejieshu);
        time_pickerkaishi = (TimePicker) findViewById(R.id.time_pickerkaishi);
        time_pickerjieshu = (TimePicker) findViewById(R.id.time_pickerjieshu);
        time_pickerkaishi.setIs24HourView(true);
        time_pickerjieshu.setIs24HourView(true);


    }

    class TimeListenerKaishi implements TimePicker.OnTimeChangedListener {

        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            // TODO Auto-generated method stub
            tv_timekaishi.setText("开始时间:" + hourOfDay + ":" + minute);

        }

    }


    class TimeListenerJieshu implements TimePicker.OnTimeChangedListener {


        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            // TODO Auto-generated method stub
            tv_timejieshu.setText("结束时间:" + hourOfDay + ":" + minute);

        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }

    @Override
    public void initListeners() {
        time_pickerkaishi.setOnTimeChangedListener(new TimeListenerKaishi());
        time_pickerjieshu.setOnTimeChangedListener(new TimeListenerJieshu());
        gv_business.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int select,
                                    long arg3) {
                if (mMyGridViewchoiceTimeAdpter.lists.get(select).isSelect()) {
                    mMyGridViewchoiceTimeAdpter.lists.get(select).setSelect(false);
                } else {
                    mMyGridViewchoiceTimeAdpter.lists.get(select).setSelect(true);
                }

                mMyGridViewchoiceTimeAdpter.notifyDataSetChanged();//更新列表
            }
        });
    }


    @Override
    public void initData() {

        tv_timekaishi.setText("开始时间:" + time_pickerkaishi.getCurrentHour() + ":" + time_pickerkaishi.getCurrentMinute());
        tv_timejieshu.setText("结束时间:" + time_pickerjieshu.getCurrentHour() + ":" + time_pickerjieshu.getCurrentMinute());
        listDatas = new ArrayList<ProdctBean>();


        ProdctBean p1 = new ProdctBean();
        p1.setName("周一");
        ProdctBean p2 = new ProdctBean();
        p2.setName("周二");
        ProdctBean p3 = new ProdctBean();
        p3.setName("周三");
        ProdctBean p4 = new ProdctBean();
        p4.setName("周四");
        ProdctBean p5 = new ProdctBean();
        p5.setName("周五");
        ProdctBean p6 = new ProdctBean();
        p6.setName("周六");
        ProdctBean p7 = new ProdctBean();
        p7.setName("周日");
        listDatas.add(p1);
        listDatas.add(p2);
        listDatas.add(p3);
        listDatas.add(p4);
        listDatas.add(p5);
        listDatas.add(p6);
        listDatas.add(p7);


        mMyGridViewchoiceTimeAdpter = new MyGridViewchoiceTimeAdpter(this, listDatas);
        gv_business.setAdapter(mMyGridViewchoiceTimeAdpter);

    }

    @Override
    public void setHeader() {
        super.setHeader();
        rlTitle.setVisibility(View.VISIBLE);
        tvTopRighttitle.setVisibility(View.VISIBLE);
        ivTopBack.setVisibility(View.VISIBLE);
        tvTopTitle.setText("营业时间");
        tvTopRighttitle.setText("保存");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_login:

                for (int i = 0; i < mMyGridViewchoiceTimeAdpter.lists.size(); i++) {
                    if (mMyGridViewchoiceTimeAdpter.lists.get(i).isSelect()) {

                    }
                }

//                Intent intent = new Intent();
//                intent.putExtra("select_result",  mFolderList.get(positions).getImageInfoList().get(position).getImageFile().getAbsolutePath());
//                setResult(RESULT_OK, intent);
//                finish();

                break;
            case R.id.tv_top_righttitle:

                ToastUtil.makeText(ChoiceBusinessTimeActivity.this, "保存");

                break;

        }
        super.onClick(v);
    }

    @Override
    public void onError(BaseResp s) {
        Utils.bequit(s, this);
    }

    @Override
    public void onSuccess(BaseResp s) {

    }

    @Override
    public void showLoading() {
        super.showLoading();
    }

    @Override
    public void hideLoading() {
        super.hideLoading();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
